<?php
/*
$str = 'this is string';

require_once(dirname(dirname(__FILE__)) . '/include/def.php');
require_once(INCLUDE_DIR . 'functions.php');
require_once(INCLUDE_DIR . 'Factory.class.php');

DEBUG ? error_reporting(E_ALL) && ini_set('display_errors', 'off') : 
				error_reporting(0) && ini_set('display_errors', 'off');

$dbh = Factory::getDb('DEV');
$dbh or die('db connect error');

$errmsg = $dbh->realEscapeString($str);

$sql = "UPDATE msg SET errmsg = '{$errmsg}' WHERE id = 13820247183620";
$result = $dbh->query($sql);
$result or die($dbh->errno() . ': ' . $dbh->errstr());
var_dump($result);

*/

$time = '15';
$str = date('H', strtotime($time));
var_dump($str);


function convertTimeParam($str, $type = null)
	{
		if (!$type) {
			if (!isset($this->options['type']) && $this->options['type']) {
				$type = $this->options['type'];
			} else {
				return false;
			}
		}
		
		if (strpos('#', $str)) {
			$str = strstr('#', ' ', $str);
		}

		$dateStr =
		$tmpStr = explode(' ', $str);
		$dateStr = array(
			'date' => $tmpStr[0], 
			'time' => isset($tmpStr[1]) ? $tmpStr[1]: null
		);

		// validate date
		if (!Hw_Util::isDate($dateStr['date'])) {// 参数错误(日期)
			return false;
		}

		// datetime
		$result = array(
			'date' => null, 
			'time' => null
		);
		$result['date'] = $dateStr['date'];
		switch ($type) {
			case self::STAT_TYPE_DAY :
				$result['time'] = '00:00:00';
				break;
			case self::STAT_TYPE_HOUR :
				$tmpTime = explode(':', $dateStr['time']);
				$dateStr['hour'] = (int)$tmpTime[0];
				
				if (!Hw_Util::isHour($dateStr['hour'])) {// 参数错误(小时)
					return false;
				}
				
				$result['time'] = $dateStr['hour'] . ':00:00';

				break;
			case self::STAT_TYPE_HALFHOUR :
				$tmpTime = explode(':', $dateStr['time']);
				$dateStr['hour'] = (int)$tmpTime[0];
				$dateStr['minute'] = isset($tmpTime[1]) ? (int)$tmpTime[1] : null;
				
				$minuteOptions = array(0, 30);
				if (!in_array($dateStr['minute'], $minuteOptions)) {// 参数错误(分钟)
					return false;
				}
				
				$result['time'] = $dateStr['hour'] . ':' . $dateStr['minute'] . ':00';
				if (!Hw_Util::isTime($result['time'])) {
					return false;
				}

				break;
			default :
				return false;
		}

		return $result;
	}